

/** 视频投射
 * @param {String} url 视频地址
 */
activeVideo(url) {

    // 创建视频 dom
    const video = this._createVideoEle(url);
    const thisObject = this;
    if (video) {
        const viewer = this.viewer;
        // 等待视频载入
        let waitingVideo = true;
        // 循环帧监听事件
        this.activeVideoListener || (this.activeVideoListener = function () {

            thisObject.videoTexture && thisObject.videoTexture.destroy();

            // 解决为加载视频警告
            video.addEventListener('loadeddata', function () {
                waitingVideo = false;
            });

            // 创建视频纹理
            thisObject.videoTexture = new Texture({
                context: viewer.scene.context,
                source: waitingVideo ? undefined : video,
                width: 1,
                height: 1,
                pixelFormat: PixelFormat.RGBA,
                pixelDatatype: PixelDatatype.UNSIGNED_BYTE
            });
        });
        viewer.clock.onTick.addEventListener(this.activeVideoListener);
    }
}



// 创建阴影对象
_createShadowMap() {
    // 创建相机
    const lightCamera = this._getCamera();
    // 计算远距离
    const pointLightRadius = Cartesian3.distance(this.position, this.cameraPosition);
    // 相机视椎
    lightCamera.frustum = new PerspectiveFrustum({
        fov: CesiumMath.toRadians(this.fov),
        aspectRatio: this.aspectRatio,
        near: this.near,
        far: pointLightRadius
    });
    // 计算生成阴影
    this.viewShadowMap = new ShadowMap({
        lightCamera,
        enable: !1,
        // 点光源
        isPointLight: !1,
        // 聚光灯
        isSpotLight: !0,
        cascadesEnabled: !1,
        context: this.viewer.scene.context,
        pointLightRadius,
        // 阴影处亮度
        darkness: 1 - this.param.shadowDarkness,
    });
}



// 创建视锥
_addCameraFrustum() {
    this.cameraFrustum = new Primitive({
        geometryInstances: new GeometryInstance({
            geometry: new FrustumOutlineGeometry({
                origin: this.cameraPosition,
                orientation: this.orientation,
                frustum: this.viewShadowMap._lightCamera.frustum,
                _drawNearPlane: !0
            }),
            attributes: {
                color: ColorGeometryInstanceAttribute.fromColor(new Color(0, 1, 1))
            }
        }),
        appearance: new PerInstanceColorAppearance({
            translucent: !1,
            flat: !0
        }),
        asynchronous: !1,
        show: this.debugFrustum && this.show
    });
    this.viewer.scene.primitives.add(this.cameraFrustum);
}

// 创建后处理
_addPostProcess() {

    const thisObject = this;
    const _bias = this.viewShadowMap._isPointLight ?
        this.viewShadowMap._pointBias : this.viewShadowMap._primitiveBias;

    // glsl 统一变量值
    const uniforms = {
        mixNum: function () {
            return thisObject.alpha;
        },
        stcshadow: function () {
            return thisObject.viewShadowMap._shadowMapTexture;
        },
        videoTexture: function () {
            return thisObject.videoTexture;
        },
        _shadowMap_matrix: function () {
            return thisObject.viewShadowMap._shadowMapMatrix;
        },
        shadowMap_texelSizeDepthBiasAndNormalShadingSmooth: function () {
            const t = new Cartesian2();
            t.x = 1 / thisObject.viewShadowMap._textureSize.x;
            t.y = 1 / thisObject.viewShadowMap._textureSize.y;
            return Cartesian4.fromElements(
                t.x, t.y, _bias.depthBias, _bias.normalShadingSmooth, this.combinedUniforms1);
        },
        shadowMap_normalOffsetScaleDistanceMaxDistanceAndDarkness: function () {
            return Cartesian4.fromElements(
                _bias.normalOffsetScale, thisObject.viewShadowMap._distance,
                thisObject.viewShadowMap.maximumDistance, thisObject.viewShadowMap._darkness,
                this.combinedUniforms2);
        }

    };

    // 创建后处理
    this.postProcess = new PostProcessStage({
        fragmentShader,
        uniforms: uniforms
    });
    this.viewer.scene.postProcessStages.add(this.postProcess);
}


